package com.webdiy.dfss.impl;

import com.sys.plat.service.base.BaseServiceImpl;
import com.sys.tool.FetionTool;
import com.sys.tool.MailTool;
import com.webdiy.dao.model.DfssUserInfo;
import com.webdiy.dfss.iface.UserService;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: mabo
 * Date: 2009-11-25
 * Time: 16:00:06
 * To change this template use File | Settings | File Templates.
 */
public class UserServiceImpl extends BaseServiceImpl implements UserService {
    public DfssUserInfo login(String userCode, String userPassWord) {
        List list = this.dao.listByHql("FROM DfssUserInfo WHERE userCode = ? AND userPassWord = ?", userCode, userPassWord);
        if (list.size() > 0) {
            return (DfssUserInfo) list.get(0);
        }
        return null;
    }


    public void saveUser(final DfssUserInfo d) {
        if (d.getId() != null && !d.getId().equals("")) {
            this.dao.updateObject(d);
        } else {
            this.dao.saveObject(d);
            Thread th = new Thread(new Runnable() {
                public void run() {
                    MailTool mt = new MailTool("mabo@ec.com.cn","56789mb","mail.ec.com.cn");
                    mt.post(d.getUserMail(), "欢迎使用东方时尚自动约车系统【系统邮件】", "\n\n\n欢迎使用东方时尚自动约车系统【系统邮件】\n\n\n本系统提供飞信消息提示功能，系统会自动加您为好友（需移动用户）。");
                    FetionTool.addBuddy(d.getMobile(), "dfss预约");
                    FetionTool.sendSms(d.getMobile(), "欢迎使用东方时尚自动约车系统【系统信息】");
                }
            });
            th.start();
        }
    }

    public List findUser() {
        return this.dao.listByHql("FROM DfssUserInfo");
    }
}
